/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.db;

import com.ttt.nor2.util.ExceptionUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Hashtable;
import org.apache.log4j.Logger;

/**
 *
 * @author anuphabm
 */
public class HtbALarmDesc {

    private Logger logger = Logger.getLogger(HtbALarmDesc.class);
    private Connection conn;

    public HtbALarmDesc(Connection conn) {
        this.conn = conn;
        logger.debug("Start class HtbALarmDesc...");
    }

    public Hashtable loadData() {

        Hashtable ht = new Hashtable();
        try {
            String sql = "SELECT w.alarm_num, w.status_alarm,a.alarm_desc_en,a.alarm_desc_th  ";
            sql += "FROM work_alarm AS w Inner Join alarm_desc AS a ON w.alarm_num = a.alarm_num  ";
            sql += "WHERE w.status_alarm = 'Y' and w.day_alarm = DAYOFWEEK(now())";
            sql += " and  (date_format(now(),'%H%i') > w.time_alarm_b ";
            sql += "or date_format(now(),'%H%i') < w.time_alarm_e) ";
            logger.debug("[" + sql + "]");
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                ALarmDescription alarm = new ALarmDescription();
                alarm.setAlarm_desc_en(rs.getString("alarm_desc_en"));
                alarm.setAlarm_desc_th(rs.getString("alarm_desc_th"));
                String numAlarm = rs.getString("alarm_num");
                ht.put(numAlarm, alarm);
                logger.debug("[" + numAlarm + "]");
            }
        } catch (Exception e) {
            logger.error("Exception load class name HtbALarmDesc " + ExceptionUtil.getStackTrace(e));
        }
        return ht;
    }
}
